# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=srecord
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.64
pkgrel=1
pkgdesc="The SRecord package is a collection of powerful tools for manipulating EPROM load files (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('GPL')
url="https://srecord.sourceforge.io/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libgpg-error"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt")
makedepends=("${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-ghostscript"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "groff")
source=("https://sourceforge.net/projects/srecord/files/srecord/${pkgver}/srecord-${pkgver}.tar.gz"
        "0001-undef-msvcrt-config-messy.patch"
        "0002-remove-test-gecos-makefile.patch")
sha256sums=('49a4418733c508c03ad79a29e95acec9a2fbc4c7306131d2a8f5ef32012e67e2'
            '28c3025ba0fd7f766252542c65580af662771c95d55a167d790fb37092b00104'
            '80dba34a1ad3a60b68e3f4ccf68bfc324655196bac20483a65e519730a66cd5d')

prepare() {
    cd "$srcdir/${_realname}-$pkgver"
    patch -p1 -i "$srcdir/0001-undef-msvcrt-config-messy.patch"
    patch -p1 -i "$srcdir/0002-remove-test-gecos-makefile.patch"
}

build() {
  [[ -d "${srcdir}/build-${CARCH}" ]] && rm -rf "${srcdir}/build-${CARCH}"
  cp -rf "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make -j1
}

package() {
    cd "${srcdir}/build-${CARCH}"
    make DESTDIR="$pkgdir" install
}
